package com.rongxun.widget;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Paint;
import android.os.CountDownTimer;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.widget.TextView;

import com.rongxun.hbwallet.R;

/**
 * 创建者     庄丰泽
 * 创建时间   2018/8/17 9:27
 * 描述	      时间控件
 */

@SuppressLint("AppCompatCustomView")
public class TimeTexView extends TextView {

    private Context mContext;
    CountDownTimer timer;
    public TimeTexView(Context context) {
        super(context);
        mContext=context;
    }

    public TimeTexView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mContext=context;
        init();
    }

    public TimeTexView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    private void init(){
         TimeTexView.this.setPaintFlags(Paint. UNDERLINE_TEXT_FLAG ); //下划线
         timer = new CountDownTimer(60*1000, 1000) {
         @Override
        public void onTick(long millisUntilFinished) {
             TimeTexView.this.setText(String.format(mContext.getString(R.string.reget), millisUntilFinished/1000));
             TimeTexView.this.setEnabled(false);
         }
        @Override
         public void onFinish() {
            TimeTexView.this.setText(mContext.getString(R.string.get_code));
            TimeTexView.this.setEnabled(true);
           }
        };
    }
    public void startTime(){
        timer.start();
    }
}
